﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CDB.LinqModel;
using CDB.LinqModel.Data;
using CDB.LinqData;

public partial class BuilderDetail : System.Web.UI.Page
{
    #region Variable Declration
    IDataRepository _dataObject = new DataRepository();
    BuilderWork bWork;
    Builder builder;
    List<BuilderWork> bWorks = new List<BuilderWork>();
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            if (Request.QueryString["Id"] != null)
            {
                fillBanners(Convert.ToInt32(Request.QueryString["Id"].ToString()));
                fillBuilderDetail(Convert.ToInt32(Request.QueryString["Id"].ToString()));
                fillProjectDetail(Convert.ToInt32(Request.QueryString["Id"].ToString()));
            }

        }
    }
    private void fillBanners(int builderId)
    {
        bWork = new BuilderWork(_dataObject);
        bWork.BuilderId = builderId;
        bWorks = bWork.GetAllWorksByBuilderId();

        if (bWorks != null)
        {
            for (int i = 0; i < bWorks.Count; i++)
            {
                topbanners.InnerHtml += "<li><div class=\"bannerImage\"><img style='width:930px !important; height:303px !important;' src='builderWorks/" + builderId.ToString() + "/" + bWorks[i].ProjectImage + "' /></div></li>";
            }
        }
    }
    private void fillBuilderDetail(int builderId)
    {
        builder = new Builder(_dataObject);
        builder.Id = builderId;
        builder.GetBuilderById();

        if (builder.Id != 0)
        {
            heading.InnerHtml = builder.Name;
            dvDescription.InnerHtml = "<strong>Description:</strong><br />" + builder.DescriptionLine;
            dvRightPanel.InnerHtml = "<strong>Address:</strong><br />" + builder.AddressLine + "<br /><strong>Phone: </strong>" + builder.Phone + " <br /><strong>Fax: </strong>" + builder.Fax + "<br />" + builder.Email + "<br /><a href='http://" + builder.Website + "' target='_blank'>" + builder.Website + "</a><hr />";
        }
    }
    private void fillProjectDetail(int builderId)
    {
        bWork = new BuilderWork(_dataObject);
        bWork.BuilderId = builderId;
        bWorks = bWork.GetAllWorksByBuilderId();

        if (bWorks.Count > 0)
        {
            for (int i = 0; i < bWorks.Count; i++)
            {
                projectLine.InnerHtml += "<div style='float:left;width:150px;'><img src='builderWorks/" + bWorks[i].BuilderId.ToString() + "/" + bWorks[i].ProjectImage + "'></a></div>";
                projectLine.InnerHtml += "<div style='float:left; margin-left:20px;width: 730px;'>" + bWorks[i].DescriptionLine + "</div> <div style='clear:both;'></div><hr />";
            }
        }
    }
}